package com.asktgapp.application;

import android.app.Activity;
import android.app.Application;
import android.app.Notification;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.support.multidex.MultiDex;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.Toast;

import com.asktgapp.JGTool.Utils;
import com.asktgapp.MyConstant;
import com.asktgapp.R;
import com.asktgapp.architecture.retrofit.ApiException;
import com.asktgapp.architecture.retrofit.ApiResponseBody;
import com.asktgapp.architecture.rxjava.ExceptionHandle;
import com.asktgapp.dialog.TokenInvalidDialog;
import com.asktgapp.hxsg.BiuEaseHelper;
import com.asktgapp.model.DifferentTypeVO;
import com.asktgapp.modulebase.common.util.PreferencesUtil;
import com.asktgapp.modulebase.common.util.Util;
import com.asktgapp.user.UpgradeActivity;
import com.asktgapp.user.activity.EngineerDetailActivity;
import com.asktgapp.user.activity.EngineerListActivity;
import com.asktgapp.user.activity.FreeAskAnswerDetailActivity;
import com.asktgapp.user.activity.HomeServiceActivity;
import com.asktgapp.user.activity.HomeServiceDetailActivity;
import com.asktgapp.user.activity.IndurstryInformationActivity;
import com.asktgapp.user.activity.IndustryInfoDetailActivity;
import com.asktgapp.user.activity.LoginActivity;
import com.asktgapp.user.activity.MainActivity;
import com.asktgapp.user.activity.NewWebActivity;
import com.asktgapp.user.activity.QiuZuDetailActivity;
import com.asktgapp.user.activity.RentDetailActivity;
import com.asktgapp.user.activity.RentMachineNewActivity;
import com.asktgapp.user.activity.SplashActivity;
import com.asktgapp.user.activity.SystemMessageActivity;
import com.asktgapp.user.activity.SystemPushActivity;
import com.asktgapp.user.activity.UsedMachineDetailActivity;
import com.asktgapp.user.activity.UsedSecondhandTypeActivity;
import com.asktgapp.utils.DifferentNotifications;
import com.sobot.chat.SobotApi;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.beta.Beta;
import com.tencent.bugly.beta.UpgradeInfo;
import com.tencent.bugly.beta.upgrade.UpgradeListener;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.message.IUmengRegisterCallback;
import com.umeng.message.MsgConstant;
import com.umeng.message.PushAgent;
import com.umeng.message.UmengMessageHandler;
import com.umeng.message.UmengNotificationClickHandler;
import com.umeng.message.entity.UMessage;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;

import org.android.agoo.huawei.HuaWeiRegister;
import org.android.agoo.mezu.MeizuRegister;
import org.android.agoo.oppo.OppoRegister;
import org.android.agoo.xiaomi.MiPushRegistar;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * time:2018/1/4
 * Create By ZhaoKai
 * Email: dczk@foxmail.com
 * Description:
 */

public class MyApplication extends Application {
    public static IWXAPI mWxApi;
    public static PushAgent mPushAgent;
    public static MyApplication mInstance;
    public static UMShareAPI ShareAPI;
    public static String mAskEngineerID = "";
    public static String mAskEngineerHeadIMG = "";
    public static String mAskEngineerName = "";
    public static int mAskType = 0;
    public static String UmengToken;
    public static int isAskAgain;
    private List<Activity> mList = new LinkedList<Activity>();
    public int count = 0;
    public static boolean isNotFront = false;
    public static boolean onePixelStart = false;
    public static final String APP_ID = "306aecfe60";
    public boolean showSplash = true;
    public boolean READ_PHONE_PERMISSION = false;
    public static MyApplication getInstance() {
        return mInstance;
    }

    public void addActivity(Activity activity) {
        if (!mList.contains(activity)) {
            mList.add(activity);
        }
    }

    public void removeActivity(Activity activity) {
//判断当前集合中存在该Activity
        if (mList.contains(activity)) {
            mList.remove(activity);//从集合中移除
//            activity.finish();//销毁当前Activity
        }
    }

    public void removeALLActivity() {
        //通过循环，把集合中的所有Activity销毁
        for (Activity activity : mList) {
            activity.finish();
        }
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;

        SobotApi.initSobotSDK(this, "9d6b46705cd648b9bf1b66be4a9438bf", "");
        SobotApi.setNotificationFlag(this,true, R.mipmap.logo, R.mipmap.logo);
        SobotApi.setEvaluationCompletedExit(this,true);
//        Config.DEBUG = true;
        /**
         * 初始化common库
         * 参数1:上下文，不能为空
         * 参数2:友盟 app key
         * 参数3:友盟 channel
         * 参数4:设备类型，UMConfigure.DEVICE_TYPE_PHONE为手机、UMConfigure.DEVICE_TYPE_BOX为盒子，默认为手机
         * 参数5:Push推送业务的secret
         */
        UMConfigure.init(this, "5a73f99fb27b0a50ad000079", "UM",
                UMConfigure.DEVICE_TYPE_PHONE, "e3feb5d53b423a27cc53b938bca5bf86");
        //79bm51pzhfyspgvafoueh8gwcjppqv9s  Umeng Message Secrete
//        UMConfigure.setLogEnabled(true);
        ShareAPI = UMShareAPI.get(this);
//        UMShareAPI.get(this);
        MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_UM_NORMAL);
        setUmeng();
        setUmengShare();
        BiuEaseHelper.getInstance().init(mInstance);
        registerActivityLifecycleCallbacks(new SwitchBackgroundCallbacks());
// * 开发者如果担心sdk初始化影响app启动速度，可以设置为false
        Beta.autoInit = true;
        /**
         * true表示初始化时自动检查升级
         * false表示不会自动检查升级，需要手动调用Beta.checkUpgrade()方法
         */
        Beta.autoCheckUpgrade = true;
        /**
         * 设置升级周期为60s（默认检查周期为0s），60s内SDK不重复请求策略
         */
        Beta.initDelay = 60 * 1000;

        /**
         * 设置通知栏大图标，largeIconId为项目中的图片资源；
         */
        Beta.smallIconId = R.mipmap.logo;

        /**
         * 设置状态栏小图标，smallIconId为项目中的图片资源id;
         */
        Beta.smallIconId = R.mipmap.logo;

        Beta.initDelay = 30 * 1000;

        /**
         * 设置更新弹窗默认展示的banner，defaultBannerId为项目中的图片资源Id;
         * 当后台配置的banner拉取失败时显示此banner，默认不设置则展示“loading“;
         */
        Beta.defaultBannerId = R.mipmap.default_banner;
        /**
         * 设置sd卡的Download为更新资源保存目录;
         * 后续更新资源会保存在此目录，需要在manifest中添加WRITE_EXTERNAL_STORAGE权限;
         */
        Beta.storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

        /**
         * 点击过确认的弹窗在APP下次启动自动检查更新时会再次显示;
         */
        Beta.showInterruptedStrategy = true;
        /**
         * 自定义Activity参考，通过回调接口来跳转到你自定义的Actiivty中。
         */
        Beta.upgradeListener = new UpgradeListener() {

            @Override
            public void onUpgrade(int ret, UpgradeInfo strategy, boolean isManual, boolean isSilence) {
                if (strategy != null) {
                    Intent i = new Intent();
                    i.setClass(getApplicationContext(), UpgradeActivity.class);
                    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(i);
                } else {
//                    Toast.makeText(getApplicationContext(), "没有更新", Toast.LENGTH_SHORT).show();
                }
            }
        };

        Bugly.init(getApplicationContext(), MyApplication.APP_ID, true);
        //小米
        MiPushRegistar.register(this, "2882303761517553607", "5601755344607");
        //华为
        HuaWeiRegister.register(this);
        //魅族
        MeizuRegister.register(this, "121334", "53f3569fd73f4a8f9af4e2acb3020e71");
        //oppo
        OppoRegister.register(this, "BpSITLu4Wpw04WwsKccG48oKg", "F879802C6b50b725CFd1752f53b34219");
    }


    private void setUmengShare() {

        PlatformConfig.setWeixin(MyConstant.WEIXIN_AppID, MyConstant.WEIXIN_AppSecret);
        PlatformConfig.setQQZone(MyConstant.QQ_AppID, MyConstant.QQ_AppKEY);
    }

    private void setUmeng() {
        mPushAgent = PushAgent.getInstance(this);

        //注册推送服务，每次调用register方法都会回调该接口
        mPushAgent.register(new IUmengRegisterCallback() {
            @Override
            public void onSuccess(String deviceToken) {
                UmengToken = deviceToken;
                //注册成功会返回device token
                Log.i("UmengToken", UmengToken);

            }

            @Override
            public void onFailure(String s, String s1) {
                Log.i("UmengToken", UmengToken + "s=" + s + "   s1=" + s1);
//                LogUtil.LogE(s);
            }
        });


//        mPushAgent.setDebugMode(BuildConfig.LOG_DEBUG);
        UmengMessageHandler handler = new UmengMessageHandler() {
            @Override
            public void dealWithNotificationMessage(Context context, UMessage msg) {
                //调用super则会走通知展示流程，不调用super则不展示通知
                notReadMessageNum();

//                //管理锁屏的一个服务
//                KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
//                String text = km.isKeyguardLocked() ? "锁屏了" : "屏幕亮着的";
//                Log.i("ggggggggg", "text: " + text);
//                if (km.inKeyguardRestrictedInputMode()) {
//                    Log.i("ggggggggg", "onReceive:锁屏了 ");
//
//                }
//                if (NetworkUtils.isBackground()) {
//                    //判断是否锁屏
//                    Intent alarmIntent = new Intent(context, MessageActivity.class);
//                    //在广播中启动Activity的context可能不是Activity对象，所以需要添加NEW_TASK的标志，否则启动时可能会报错。
//                    alarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                    alarmIntent.putExtra("content", msg.text);
//                    alarmIntent.putExtra("type", msg.extra.get("type"));
//                    alarmIntent.putExtra("ref_id", msg.extra.get("ref_id"));
//                    alarmIntent.putExtra("ref_type", msg.extra.get("ref_type"));
//                    context.startActivity(alarmIntent); //启动显示锁屏消息的activity
//                } else
                super.dealWithNotificationMessage(context, msg);
            }

            @Override
            public Notification getNotification(Context context, UMessage uMessage) {
                HashMap<String, String> map = (HashMap<String, String>) uMessage.extra;
//                super.getNotification(context, uMessage).visibility = Notification.VISIBILITY_PUBLIC;
                return super.getNotification(context, uMessage);
            }
        };
        mPushAgent.setMessageHandler(handler);
        mPushAgent.setMuteDurationSeconds(10);
        mPushAgent.setDisplayNotificationNumber(1);
        mPushAgent.setNotificationPlaySound(MsgConstant.NOTIFICATION_PLAY_SERVER); //声音
        mPushAgent.setNotificationPlayLights(MsgConstant.NOTIFICATION_PLAY_SERVER);//呼吸灯
        mPushAgent.setNotificationPlayVibrate(MsgConstant.NOTIFICATION_PLAY_SERVER);//振动
        UmengNotificationClickHandler notificationClickHandler = new UmengNotificationClickHandler() {
            @Override
            public void dealWithCustomAction(Context context, UMessage msg) {
                Log.i("hx", "进入了处理");
                Log.i("hx", msg.extra.toString());
                if (msg.extra != null) {
                    Log.i("hx", msg.extra.toString());
//                    BiuEaseHelper.loginIn();
                    HashMap<String, String> map = (HashMap<String, String>) msg.extra;
                    Log.i("hx", map.toString());
//                    int ref_type = Integer.parseInt(map.get("ref_type"));
                    String ref_type = map.get("ref_type");
                    String ref_id = map.get("ref_id");
                    String huanxin_id = map.get("huanxin_id");
                    String cid = map.get("cid");
                    String user_id = map.get("user_id");
                    String toUserName = map.get("username");
                    String pic = map.get("user_pic");
                    int type = Integer.parseInt(map.get("type"));
                    if (type == 2) {
                        Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);
                    } else if(type==100){
                        Intent intent;
                        switch (ref_type){
                            case "二手设备列表":
                                intent =new Intent(getApplicationContext(), UsedSecondhandTypeActivity.class);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                startActivity(intent);
                                break;
                            case "二手设备详情":
                                intent = new Intent(getApplicationContext(), UsedMachineDetailActivity.class);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.putExtra("id", ref_id);
                                startActivity(intent);
                                break;
                            case "出租找活列表":
                                intent =new Intent(getApplicationContext(), RentMachineNewActivity.class);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                startActivity(intent);
                                break;
                            case "出租找活详情":
                                intent = new Intent(getApplicationContext(), RentDetailActivity.class);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.putExtra("id", ref_id);
                                startActivity(intent);
                                break;
                            case "维修妙招列表":
                                intent =new Intent(getApplicationContext(), IndurstryInformationActivity.class);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                startActivity(intent);
                                break;
                            case "维修妙招详情":
                                intent = new Intent(getApplicationContext(), IndustryInfoDetailActivity.class);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.putExtra("id", ref_id);
                                startActivity(intent);
                                break;
                            case "上门服务列表":
                                intent =new Intent(getApplicationContext(), HomeServiceActivity.class);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                startActivity(intent);
                                break;
                            case "上门服务详情":
                                intent = new Intent(getApplicationContext(), HomeServiceDetailActivity.class);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.putExtra("id", ref_id);
                                startActivity(intent);
                                break;
                            case "工程师列表":
                                intent =new Intent(getApplicationContext(), EngineerListActivity.class);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                startActivity(intent);
                                break;
                            case "工程师详情":
                                intent = new Intent(getApplicationContext(), EngineerDetailActivity.class);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.putExtra("id", ref_id);
                                startActivity(intent);
                                break;
                            case "商城列表":
                                NewWebActivity.start(getApplicationContext(),"http://shop.jg969.com:90/client/index","找配件",1);
                                break;
                            case "商城详情":
                                NewWebActivity.start(getApplicationContext(), ref_id, "商品详情", 0);//fengyi // bean.getShopDetailUrl()

                                break;
                        }

                    }else {
                        if (type == 7 && Util.isEmpty(ref_id)) {
                            Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                        } else {

                            switch (ref_type) {
                                //二手机
                                case "0":
                                    Intent intent0 = new Intent(getApplicationContext(), UsedMachineDetailActivity.class);
                                    intent0.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                    intent0.putExtra("id", ref_id);
                                    startActivity(intent0);
                                    break;
                                //设备出租
                                case "1":
                                    Intent intent1 = new Intent(getApplicationContext(), RentDetailActivity.class);
                                    intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                    intent1.putExtra("id", ref_id);
                                    startActivity(intent1);
                                    break;
                                //设备求租
                                case "2":
                                    Intent intent2 = new Intent(getApplicationContext(), QiuZuDetailActivity.class);
                                    intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                    intent2.putExtra("id", ref_id);
                                    startActivity(intent2);
                                    break;
                                //问答
                                case "3":
                                    Intent intent = new Intent(getApplicationContext(), FreeAskAnswerDetailActivity.class);
                                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                    intent.putExtra("id", ref_id);
                                    intent.putExtra("deviceId", Utils.getDeviceId(getInstance()));
                                    startActivity(intent);
                                    break;
                                case "4":
//                            int mtype;
//                            if (type == 5) {
//                                mtype = 2;
//                            } else if (type == 4) {
//                                //付费咨询结束提醒评价
//                            }
                                    if (PreferencesUtil.getBoolean(getApplicationContext(), PreferencesUtil.KEY_IS_ENGINEER)) {
                                        BiuEaseHelper
                                                .getInstance()
                                                .beginNewSingleChat(getApplicationContext()
                                                        , "", huanxin_id
                                                        , toUserName
                                                        , pic, ref_id, 2, cid, 0);
                                    } else {
                                        BiuEaseHelper
                                                .getInstance()
                                                .beginNewSingleChat(getApplicationContext()
                                                        , "", huanxin_id
                                                        , toUserName
                                                        , pic, ref_id, 0, cid, 0);
                                    }
                                    break;
                                case "5":
                                    Intent intent5 = new Intent(getApplicationContext(), SystemPushActivity.class);
                                    intent5.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                    intent5.putExtra("type", 1);
                                    intent5.putExtra("id", ref_id);
                                    startActivity(intent5);

                                    break;
                                case "6":
                                    Intent intent6 = new Intent(getApplicationContext(), SystemMessageActivity.class);
                                    intent6.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                    intent6.putExtra("type", type);
                                    intent6.putExtra("id", ref_id);
                                    startActivity(intent6);
                                    break;
                            }
                        }
                    }
                }

            }
        };
        mPushAgent.setNotificationClickHandler(notificationClickHandler);
        mPushAgent.onAppStart();
    }



    private void registToWX() {
        //AppConst.WEIXIN.APP_ID是指你应用在微信开放平台上的AppID，记得替换。
//        mWxApi = WXAPIFactory.createWXAPI(this, MyConstant.WEIXIN_AppID, false);
        // 将该app注册到微信
        mWxApi.registerApp(MyConstant.WEIXIN_AppID);
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }


    @Override
    public void onTerminate() {
        // 程序终止的时候执行

        super.onTerminate();
    }


    private class SwitchBackgroundCallbacks implements ActivityLifecycleCallbacks {

        @Override
        public void onActivityCreated(Activity activity, Bundle bundle) {

        }

        @Override
        public void onActivityStarted(final Activity activity) {
            if (count == 0) {
                isNotFront = false;
                //后台切换到前台
                if (!Util.isEmpty(PreferencesUtil.getString(activity, PreferencesUtil.USER_ID))) {
                    Apiservice apiservice = ApiUtil.getInstance().create();
                    HashMap param = new HashMap();
                    param.put("userId", PreferencesUtil.getString(activity, PreferencesUtil.USER_ID));
                    param.put("page", 1);
                    Log.v("danxx", ">>>>>>>>>>>>>>>>前台显示并请求接口"+PreferencesUtil.getString(activity, PreferencesUtil.USER_ID));
                    Call<ApiResponseBody> call1 = apiservice.notReadMessageNum(param);
                    call1.enqueue(new Callback<ApiResponseBody>() {
                        @Override
                        public void onResponse(Call<ApiResponseBody> call, Response<ApiResponseBody> response) {
                            Log.v("danxx", ">>>>>>>>>>>>>>>>前台显示并请求接口成功"+response.isSuccessful());

                            if (response.isSuccessful()) {
                                BiuEaseHelper.loginIn();
                            }
                        }

                        @Override
                        public void onFailure(Call<ApiResponseBody> call, Throwable t) {
                            ApiException apiException = ExceptionHandle.handleException(t);
                            Log.v("danxx", "前台显示网络请求失败了"+PreferencesUtil.getString(activity, PreferencesUtil.USER_ID));
                            if (apiException.isTokenInvalid()) {
                                PreferencesUtil.putString(activity, PreferencesUtil.USER_ID, "");
                                PreferencesUtil.putString(activity, PreferencesUtil.KEY_HX_ID, "");
                                BiuEaseHelper.loginOut();
                                if (!(activity instanceof SplashActivity || activity instanceof LoginActivity)) {
                                     TokenInvalidDialog dialog = new TokenInvalidDialog(null, new TokenInvalidDialog.onResultCallBack() {
                                        @Override
                                        public void onSure() {
                                            Intent intent = new Intent(activity, LoginActivity.class);
                                            intent.putExtra("reload", 1);
                                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                            startActivity(intent);
                                        }
                                    });
                                    if (activity instanceof FragmentActivity) {
                                        Log.v("danxx", "前台显示网络请求失败了 activity instanceof FragmentActivity");

                                        dialog.show(((FragmentActivity) activity).getSupportFragmentManager(), "TokenInvalidDialog");
                                    } else {
                                        Log.v("danxx", "前台显示网络请求失败了 ");
                                        Intent intent = new Intent(activity, LoginActivity.class);
                                        startActivity(intent);
                                    }

                                }

                            } else if (apiException.isNetConnected()) {
                                Log.v("danxx", "前台显示网络请求失败了apiException.isNetConnected()");

                            }
                        }
                    });
                }
            }
            count++;
        }

        @Override
        public void onActivityResumed(Activity activity) {

        }

        @Override
        public void onActivityPaused(Activity activity) {

        }

        @Override
        public void onActivityStopped(Activity activity) {
            count--;
            if (count == 0) { //前台切换到后台
                isNotFront = true;
            }
        }

        @Override
        public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {

        }

        @Override
        public void onActivityDestroyed(Activity activity) {
        }
    }


    public static boolean userIdIsEmpty(Context context) {
        String userId = PreferencesUtil.getString(context, PreferencesUtil.USER_ID);
        return Util.isEmpty(userId);
    }


    //消息接口
    private void notReadMessageNum() {
        Log.v("danxx", "推送后调用未读接口"+PreferencesUtil.getString(this, PreferencesUtil.USER_ID));
        Apiservice apiservice = ApiUtil.getInstance().create();
        HashMap params = new HashMap();
        params.put("userId", PreferencesUtil.getString(this, PreferencesUtil.USER_ID));
//        params.put("platform", "0");
//        params.put("deviceId", Utils.getDeviceId(MyApplication.getInstance()));
        params.put("page", 1);
        Call<ApiResponseBody<DifferentTypeVO>> call = apiservice.notReadMessageNum(params);
        call.enqueue(new Callback<ApiResponseBody<DifferentTypeVO>>() {
            @Override
            public void onResponse(Call<ApiResponseBody<DifferentTypeVO>> call, Response<ApiResponseBody<DifferentTypeVO>> response) {
                if (response.isSuccessful()) {
                    DifferentTypeVO bean = response.body().getResult();
                    if (bean != null) {
                        NotificationCompat.Builder builder = new NotificationCompat.Builder(getBaseContext());
//                        builder.setSmallIcon(R.drawable.stat_sys_third_app_notify);
//                        builder.setPriority(NotificationCompat.PRIORITY_MIN);
                        Notification n = builder.build();
//                        int defaults = Notification.DEFAULT_LIGHTS;
//                        defaults |= Notification.DEFAULT_SOUND;
//                        n.defaults = defaults;
                        n.flags = Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_AUTO_CANCEL;

                        if (bean.getNotReadNum() > 0) {
                            DifferentNotifications.showBubble(getBaseContext(), n, 1801, bean.getNotReadNum());
                        } else {
                            DifferentNotifications.hideBubble(getBaseContext(), n, 1801);
                        }

                    }
                }
            }

            @Override
            public void onFailure(Call<ApiResponseBody<DifferentTypeVO>> call, Throwable t) {
                Log.v("danxx", "推送后调用未读接口失败了"+PreferencesUtil.getString(getApplicationContext(), PreferencesUtil.USER_ID));
            }
        });
    }
}
